package com.xmlasia.remote.transformer;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.zip.GZIPInputStream;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.transformer.AbstractPayloadTransformer;

public class ByteUnzipTransformer extends AbstractPayloadTransformer<byte[], byte[]> {

	private final Logger logger = LoggerFactory.getLogger(ByteUnzipTransformer.class);
	
	@Override
	protected byte[] transformPayload(byte[] payload) throws Exception {
		logger.info("Length :{}", payload.length);
		ByteArrayInputStream bais = new ByteArrayInputStream(payload);
		GZIPInputStream gzis = new GZIPInputStream(bais);
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		IOUtils.copy(gzis, baos);
		byte[] output = baos.toByteArray();
		logger.info("Size :{}", baos.size());
		return output;
//		logger.info("$$$$");
//		return payload;
	}

}
